/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-09-12
 * Time: 18:22
 */

//自定义异常
class NameException extends RuntimeException{
    public NameException(String message) {
        super(message);
    }
}
class PasswordException extends RuntimeException{
    public PasswordException(String message) {
        super(message);
    }
}
public class TestDemo2 {
    private static final String name = "bit";
    private static final String password = "123";

    public static void login(String name, String password)throws NameException,PasswordException{
        if (!TestDemo2.name.equals(name)){
            throw new NameException("用户名错误");
        }
        if (!TestDemo2.password.equals(password)){
            throw new PasswordException("密码错误");
        }
    }

    public static void main(String[] args) {
        try {
            login("bit", "1234");
        }catch (NameException e){
            e.printStackTrace();
            System.out.println("用户名错误");
        }catch (PasswordException e){
            e.printStackTrace();
            System.out.println("密码错误");
        }finally {
            System.out.println("执行成功");
        }
    }
}
